@extends('app')
@include('UEditor::head')
@section('content')
{{-- 表单验证错误信息 --}}
@if(!empty($errors))
    @if ($errors->any())
        <div class="alert alert-danger">
            @foreach($errors->all() as $error)
                <p>{{ $error }}</p>
            @endforeach
        </div>
    @endif
@endif
<ul class="nav nav-tabs">
    <li ><a href="{{ url('/admin/enterprise/questions')}}">题库管理</a></li>
    <li class="active"><a href="{{ url('/admin/enterprise/questions/create') }}">添加</a></li>
</ul>
<form class="" id="questionsForm" method="post">
    <div class="panel panel-default mt20">
        <div class="form-group clearfix mt20">
            <label for="" class="col-sm-1 control-label">标题</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="title" id="title" placeholder="题目标题" value="{{ !empty($question)?$question->title:'' }}">
            </div>
        </div>
        <div class="form-group clearfix">
            <label for="" class="col-sm-1 control-label">企业</label>
            <div class="col-sm-10">
                 @if(!empty($question) && $question->company_id >0 )
                 {{ $question->getCompanyInfo->name }}                 
                 @else
                <select class="form-control" name="company_id">
                    <option value="0">系统试题</option>
                    @foreach ($companys as $cpy)
                        <option value="{{ $cpy->id }}" @if(!empty($question) && $question->company_id == $cpy->id) selected @endif>{{ $cpy->name }}</option>
                    @endforeach
                </select>
                @endif
            </div>
        </div>

        <div class="form-group clearfix">
            <label for="" class="col-sm-1 control-label">选项</label>
            <div class="col-sm-10">
                <script id="container" name="options"  style="width:100%;margin:0 auto;height:300px;" type="text/plain">
                </script>
            </div>
        </div>

        <div class="form-group clearfix">
            <label for="" class="col-sm-1 control-label">答案</label>
            <div class="col-sm-10">
                <input type="text" name="answer" id="answer" class="form-control" value="{{ !empty($question)?$question->answer:'' }}">
            </div>
        </div>
        
        <div class="form-group clearfix">
            <label for="" class="col-sm-1 control-label">选项数量</label>
            <div class="col-sm-10">
                <input type="text" name="questions_num" id="questions_num" class="form-control" value="{{ !empty($question)?$question->questions_num:'' }}">
                <div class="help-block">不可为空，选项数量</div>
            </div>
        </div>

        <div class="form-group clearfix">
            <label for="" class="col-sm-1 control-label">解释</label>
            <div class="col-sm-10">
                <textarea name="explain" id="explain" class="form-control" rows="3">{{ !empty($question)?$question->explain:'' }}</textarea>
            </div>
        </div>        
        <div class="form-group clearfix">
            <label for="" class="col-sm-1 control-label">题型</label>
            <div style="padding-top:15px;">
                <input type="radio" name="questions_type" id="" value="0" @if(!empty($question) && $question->questions_type == 0)checked="checked" @else checked @endif /> 单选题
                <input type="radio" name="questions_type" id="" value="1" @if(!empty($question) && $question->questions_type == 1) checked="checked" @endif /> 多选题
            </div>
        </div>
        <input type="hidden" name="questions_id" value="{{ !empty($question)?$question->id:0 }}">
        {!! csrf_field() !!}
    </div>

    <div class="form-inline clearfix">
        <button class="btn btn-info" type="button" id="company_save" onclick="saveData('/admin/enterprise/questions','questionsForm')">
            <i class="icon-ok bigger-110"></i>
            submit
        </button>
        <button type="reset" class="btn">
            <i class="icon-undo bigger-110"></i>
            Reset
        </button>
    </div>
</form>
<script type="text/javascript">
var ue = UE.getEditor('container');
ue.ready(function() {
	ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值. 
	ue.setContent('@if(!empty($question)){!! $question->options !!}@endif');   
});
    $(document).ready(function(){
        /*复选框样式*/
        $('input[name="questions_type"]').iCheck({
            checkboxClass: 'icheckbox_flat-blue',
            radioClass: 'iradio_flat-blue',
            increaseArea: '-10' // optional
        });

        /*全选*/
        $('#checkAll').on('ifClicked', function(event){
            $('input[name="comments"]').iCheck('check');
        });
        $('#checkAll').on('ifUnchecked', function(event){
            $('input[name="comments"]').iCheck('uncheck');
        });
    });
</script>
@endsection
